<?php
	function show_interface () {
        require_once('paths.inc');
        require_once('page.inc');
        require_once(INCLUDE_PATH . 'constants.inc');
        require_once('utils.inc');

        session_start();
        select_language();
    
		
		if (isset($_GET['index']) && $_GET['index'] != -1) $index = $_GET['index'];
		$tip = $_GET['tip'];
        $id_client = $_SESSION['user_logat']->id_client;
	
		if (isset($index)) {			
			require_once(DB_PATH.'db.inc');	
			checkIsLoggedIn();
			$db = db_connect();
			$dash = Dashboard::queryGetByID($db, $id_client, $index);
			
			$text = LANG_Update;
			$opt = "update";	
		}
		else {	
			$id_user = $_SESSION['user_logat']->id_user;
			$dash = new Dashboard($id_client, $id_user, $tip);
            
            $text = LANG_ADD;
            $opt = "insert";
		}
		
		if (!isset($index)) $index = -1;
        
		if ($tip == CT_DASHBOARD_MARFA) {
            $titlu_tabel = LANG_Add_marfuri;
            $help_text = LANG_EXTRA_MODAL_DASHBORD_ADD_MARFA;
            if ($opt == "update")
                $help_text = LANG_EXTRA_MODAL_DASHBORD_EDIT_MARFA;
        }
		if ($tip == CT_DASHBOARD_CAMION) {
            $titlu_tabel = LANG_Add_camioane;
            $help_text = LANG_EXTRA_MODAL_DASHBORD_ADD_CAMION;
            if ($opt == "update")
                $help_text = LANG_EXTRA_MODAL_DASHBORD_EDIT_CAMION;
        }
	
		$ret = '<div align="center">				
					<table id="wrapper2" name="new_fash" border="0" align="center" cellpadding="3" cellspacing="0">
						<thead>
							<tr>
								<th colspan="2" align="center"> ' . $titlu_tabel . '</th>
							</tr>
						</thead>
						<tr class="capTabel">
							<td id="td_tara_plecare" align="right"><b>' . LANG_Tara_plecare . '</b></td>
							<td align="left">
								<input type="text" name="tara_plecare" id="tara_plecare" value="' . $dash->tara_plecare . '" size="' . CT_MODAL_ADD_CONT_INPUT_SIZE_TEXT_BOX . '" />
							</td>
						</tr>
						<tr class="capTabel">
							<td id="td_oras_plecare" align="right"><b>' . LANG_Oras_plecare . '</b></td>
							<td align="left">
								<input type="text" name="oras_plecare" id="oras_plecare" value="' . $dash->oras_plecare . '" size="' . CT_MODAL_ADD_CONT_INPUT_SIZE_TEXT_BOX . '" />
							</td>
						</tr>
						<tr class="capTabel">
							<td id="td_data_plecare" align="right"><b>' . LANG_Data_plecare . '</b></td>
							<td align="left">' . render_date_field_with_ora_button($dash->data_plecare, 'data_plecare', 'DHTMLSuite_modalBox_contentDiv') . '</td>							
						</tr>
						<tr class="capTabel">
							<td id="td_tara_sosire" align="right"><b>' . LANG_Tara_sosire . '</b></td>
							<td align="left">
								<input type="text" name="tara_sosire" id="tara_sosire" value="' . $dash->tara_sosire . '" size="' . CT_MODAL_ADD_CONT_INPUT_SIZE_TEXT_BOX . '" />
							</td>
						</tr>
						<tr class="capTabel">
							<td id="td_oras_sosire" align="right"><b>' . LANG_Oras_sosire . '</b></td>
							<td align="left">
								<input type="text" name="oras_sosire" id="oras_sosire" value="' . $dash->oras_sosire . '" size="' . CT_MODAL_ADD_CONT_INPUT_SIZE_TEXT_BOX . '" />
							</td>
						</tr>
						<tr class="capTabel">
							<td id="td_data_sosire" align="right"><b>' . LANG_Data_sosire . '</b></td>
							<td align="left">' . render_date_field_with_ora_button($dash->data_sosire, 'data_sosire', 'DHTMLSuite_modalBox_contentDiv') . '</td>
						</tr>
                        <tr class="capTabel">
                            <td id="td_pret" align="right"><b>' . LANG_Pret . '</b></td>
                            <td align="left"><input type="text" class="input_number" name="pret" id="pret" value="' . prepareFloatForUser($dash->pret_total) . '" /></td>
                        </tr>
						<tr class="capTabel">
							<td id="td_moneda" align="right"><b>' . LANG_Moneda . '</b></td>
                            <td align="left">' .
                            render_combobox_string("moneda", $monede_int, $currencies, $dash->moneda) .
                            '</td>
						</tr>
						<tr class="capTabel">
							<td id="td_km" align="right"><b>' . LANG_Kilometrii . '</b></td>
							<td align="left"><input type="text" class="input_number" name="km" id="km" value="' . prepareIntForUser($dash->km) . '" /></td>
						</tr>												
						<tr class="capTabel">
							<td id="td_comentariu" align="right"><b>' . LANG_Comentariu . '</b></td>
							<td align="left">
								<textarea cols="38" rows="4" name="comentariu" id="comentariu">' . $dash->comentariu . '</textarea>
							</td>
						</tr>						
						<tr class="capTabel">
							<td colspan="2" align="center">';
				$ret .='<input type="button" name="dashboard_confirm" id="dashboard_confirm" value="' . $text . '"' . "onclick=\"javascript: new_dashboard_confirm($tip,'" . $opt ."'," . $index . ");\" />&nbsp;&nbsp;";
				$ret .='<input type="button" name="dashboard_cancel" id="dashboard_cancel" value="' . LANG_CANCEL . '" onclick="javascript: closeMessage();" />
							</td>
						</tr>'
                        . output_extra_text_modal($help_text, 2) . 
					'</table>
			</div>
			<script type="text/javascript">
				document.tara_plecare.focus();
			</script>';
			echo $ret;		
			flush();
	}
	
	show_interface();			
?>